import { HomeOutlined, UserOutlined, CrownOutlined, ShoppingOutlined, OrderedListOutlined, PieChartOutlined, AppstoreOutlined } from '@ant-design/icons';

const Auth = () => {
    let token = localStorage.getItem('token')
    if (!token) {
        return false
    }
    return true
}

// 设置左侧菜单的树形结构

const menuTree = (data)=>{
    // 定义一个空树形结构
    let tree = [];

    let icons = [<UserOutlined/>,<CrownOutlined />,<ShoppingOutlined />,<OrderedListOutlined />,<PieChartOutlined />]

    if(data.length<=0){
        return tree;
    }

    //循环一级分类的数据内容
    data.forEach((item,index)=>{
        tree.push({
            label:item.authName,
            key: item.path,
            icon:icons[index],
        })
        //判断当前对象是否有children属性，如果有的话，做循环对象的属性值
        if(item.hasOwnProperty("children")){
            //先初始化一个空数组的内容
            tree[index]['children'] = [];
            //循环对象的内容值
            item.children.forEach(opt=>{
                tree[index]['children'].push({
                    label:opt.authName,
                    key: opt.path,
                    icon:<AppstoreOutlined />
                })
            })
        }
    })


    tree.unshift({
        label:"首页",
        key:"home",
        icon:<HomeOutlined/>
    })
    return tree;
}

export { Auth, menuTree }